/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.text.SimpleDateFormat;
import javax.swing.table.DefaultTableModel;
/*
 * ControlCalidad0.java
 *a.Text
 * Created on 30-ago-2011, 11:57:48
 */
/**
 *
 * @author Administrador
 */
class DefaultTableModel1 extends DefaultTableModel
{
    Class[] types = new Class [] {
            java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class
    };
    
    String [] nombres = new String[] {
            "Lote","Fecha","Seleccion"
    };
    

    public Class getColumnClass(int columnIndex) {
            return types [columnIndex];
    }
    
    public  String getColumnName(int columnIndex) {
        return nombres [columnIndex];
    }    
    public  int getColumnCount(){
            return 3;
    }
	
}

public class ControlCalidad0 extends javax.swing.JFrame {

    public static String codigo="";
    public static String nombre="";
    public static String cargo="";
    
    /** Creates new form ControlCalidad0 */
    public ControlCalidad0() {
        initComponents();
    }
    public ControlCalidad0(javax.swing.JFrame padre) {
        padre.dispose();
        initComponents();
    }
    public ControlCalidad0(javax.swing.JFrame padre,String login,String cargo_, String nombre_) {
          codigo=login;
          cargo=cargo_;
          nombre=nombre_;
        
        padre.dispose();
        initComponents();
    }
    
   // public ControlCalidad0(String login,password,cargo) {
     //   padre.dispose();
     //   initComponents();
   // }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Lote", "Fecha ", "Seleccion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        modelo = new DefaultTableModel1();
        jTable1.setModel(modelo);
        Conexion1 conexion = new Conexion1();
        Statement instruccion = null; // instrucción de consulta
        ResultSet conjuntoResultados = null; // maneja los resultados

        // se conecta a la base de datos libros y realiza una consulta
        try
        {
            // crea objeto Statement para consultar la base de datos
            instruccion = conexion.getConnection().createStatement();
            String ConsultaSQL = "SELECT LOTE.CodLote, ORDEN_PRODUCCION.FechaFin FROM  LOTE INNER JOIN ORDEN_PRODUCCION ON LOTE.CodOrdPed = ORDEN_PRODUCCION.CodOrdPed AND LOTE.CodOrdPro = ORDEN_PRODUCCION.CodOrdPro";
            // consulta la base de datos
            conjuntoResultados = instruccion.executeQuery(ConsultaSQL);
            while ( conjuntoResultados.next() )
            modelo.addRow(new Object[]{conjuntoResultados.getObject( 1 ) ,conjuntoResultados.getObject( 2 ) ,new Boolean(false)});

        }  // fin de try
        catch ( SQLException excepcionSql )
        {
            excepcionSql.printStackTrace();
        } // fin de catch
        finally // asegura que conjuntoResultados, instruccion y conexion estén cerrados
        {
            try
            {
                conjuntoResultados.close();
                instruccion.close();
                conexion.desconectar();
            } // fin de try
            catch ( Exception excepcion )
            {
                excepcion.printStackTrace();
            } // fin de catch
        } // fin de finally

        //modelo.addRow(new Object[]{"1","10/11/2011",new Boolean(true)});
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(1).setResizable(false);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(55);

        jLabel3.setText("Fecha");

        java.sql.Date fechaActual=new java.sql.Date(new java.util.Date().getTime());  //  @jve:decl-index=0:
        SimpleDateFormat formatoDeFecha = new SimpleDateFormat("dd/MM/yyyy");            ;
        jTextField3.setText(formatoDeFecha.format(fechaActual));
        //DA_43_NotFec=formatoDeFecha.format(fechaActual);

        jTextField1.setText(nombre);
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jTextField2.setText(cargo);

        jLabel1.setText("Usuario:");

        jLabel2.setText("Cargo:");

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2))
                            .addGap(18, 18, 18)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTextField2)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(25, 25, 25)
                            .addComponent(jLabel3)
                            .addGap(18, 18, 18)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addGap(18, 18, 18)
                            .addComponent(jButton2)))
                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    
          int indice=-1;
      int contador=0;
      for (int i = 0; i < modelo.getRowCount(); i++) {
    	  if(Boolean.parseBoolean(jTable1.getValueAt(i,2).toString())==true)
    	  {
    		  contador++;    		      	  
    		  indice=i;
    		  System.out.println(indice);
    		  System.out.println(contador);
    	  }
      };
      if(contador==1)
      {
         String numLote = jTable1.getValueAt(indice,0).toString();
      ControlCalidad1 frm = new ControlCalidad1(this,numLote);
        frm.setVisible(true);
      }
        
         
                   //System.e
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed
//
    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed
//
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
            System.exit(0);        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ControlCalidad0().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables
DefaultTableModel1 modelo = null;
}
